package com.lagou.service.impl;

import com.lagou.anno.Autowired;
import com.lagou.anno.Service;
import com.lagou.anno.Transactional;
import com.lagou.dao.AccountDao;
import com.lagou.pojo.Account;
import com.lagou.service.TransferService;


@Service
public class TransferServiceImpl implements TransferService {

   /* private AccountDao accountDao = new JdbcAccountDaoImpl();*/
    //1.用反射代替new关键字，进行解耦合
    @Autowired
    private AccountDao accountDao ;


    @Override
    @Transactional
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
        Account from = accountDao.queryAccountByCardNo(fromCardNo);
        Account to = accountDao.queryAccountByCardNo(toCardNo);

        from.setMoney(from.getMoney()-money);
        to.setMoney(to.getMoney()+money);

        accountDao.updateAccountByCardNo(to);
        //int i=1/0;
        accountDao.updateAccountByCardNo(from);
    }
}
